<template>
  <div>
    <van-field label="标题" v-model="form.title"></van-field>
    消息类型
    <select name="" id="" v-model="form.notice_type">
      <option value="1">消息系统</option>
      <option value="2">通知公告</option>
    </select>
    <br>
    优先级
    <select name="" id="" v-model="form.level">
      <option value="1">高级</option>
      <option value="2">中级</option>
      <option value="3">低级</option>
    </select>
    <br>
    通知类型
    <select name="" id="" @change="changettype" v-model="form.type">
      <option value="1">所有用户</option>
      <option value="2">选择角色</option>
      <option value="3">选择用户</option>
    </select>

    <el-dialog v-model="dialogTableVisible" title="Shipping address">
      <depttree @setids="handleNodeClick"></depttree>
    </el-dialog>
    <br>
    内容
    <teditor v-model="content"></teditor>

<!--    展示内容-->
<!--    <div v-html="content" id="content"></div>-->

    <van-button @click="submit">提交</van-button>

  </div>
</template>

<script>
import TEditor from "./TEditor"
import depttree from "@/components/comm/depttree";
import axios from "axios";
export default {
  name: "addnotice",
  components: {
    'teditor': TEditor,
    'depttree': depttree,
  },
  data() {
    return {
      content: '',
      form:{'content':'','user_ids':'',},
      dialogTableVisible:false,
      checkdvalues:[],
    }
  },
  methods: {
    changettype(){
      if (this.form.type == 2 || this.form.type == 3){
        this.dialogTableVisible = true
      }
    },
    //获取角色
    // getcomanyuser(){
    //   axios.get('/getcomanyuser').then(res=>{
    //     console.log(res);
    //     this.data = res.data.list
    //   })
    // },
    // handleNodeClick(val1,status){
    //   this.checkdvalues=[]
    //   let list = status['checkedNodes']
    //   for(var i=0;i<list.length;i++){
    //     if(list[i]['type'] == 3){
    //       this.checkdvalues.push(list[i]['id'])
    //     }
    //   }
    //   this.$emit('serids',this.checkdvalues)
    // },
    submit(){
      // 更新内容到this.form，如果为2或3的时候把通知人写到数据库
      this.form.content = this.content
      this.form.user_ids = this.checkdvalues
      axios.post('/notice',this.form)
      .then(res=>{
        console.log(res)
      })
    },
    handleNodeClick(values){
      this.checkdvalues = values
    }
  },
  mounted() {

  }
}
</script>

<style scoped>

</style>
